const app = Vue.createApp({
    data() {
        return {
            rankData: [], // 排行榜数据
            today: ''
        }
    },
    methods: {
        // 获取排行榜数据
        getRank() {
            const currentDate = new Date();
            const year = currentDate.getFullYear(); // 年份
            const month = currentDate.getMonth() + 1; // 月份（注意月份从 0 开始，所以需要加 1）
            const day = currentDate.getDate(); // 日期
            const today = year + '-' + month + '-' + day
            this.today = today
            fetch('http://localhost:8090/api/rank?date=' + today)
                .then(response => response.json())
                .then(data => {
                    this.rankData = data
                })
                .catch(error => {
                    console.error(error);
                });
        },
        timeFormatter(row, column, cellValue, index) {
            return this.formatTime(cellValue)
        },
        diffFormatter(row, column, cellValue, index) {
            switch (cellValue) {
                case '1':
                    return "简单"
                case '2':
                    return "中等"
                case '3':
                    return "困难"
                default:
                    return "简单"
            }
        },
        // 格式化时间
        formatTime(time) {
            let hours = Math.floor(time / 3600);
            let minutes = Math.floor((time % 3600) / 60);
            let seconds = time % 60;

            // 将时间补零到两位数
            let formattedHours = String(hours).padStart(2, "0");
            let formattedMinutes = String(minutes).padStart(2, "0");
            let formattedSeconds = String(seconds).padStart(2, "0");

            return `${formattedHours}:${formattedMinutes}:${formattedSeconds}`;
        },


        

    },
    // 页面挂载之前执行
    mounted() {
        this.getRank()
    },
    updated() {

    }
})
app.use(ElementPlus);
app.mount("#rank")